package com.gdcnano.nanoamp.media.sound.playlist
{
    import com.gdcnano.libs.xspf4x.XSPF4X;
    import com.gdcnano.libs.xspf4x.XSPFTrack;
    
    import flash.events.Event;
    
    import mx.collections.ArrayCollection;
    
    
    /**
     * Represents XSPF playlist format
     *
     * @see http://xspf.xiph.org/ for the detailed format description
     *
     * @author gareevm
     *
     */
    public class XSPFPlaylist extends AbstractPlaylist
    {
        private var _xspf:XSPF4X;
        
		
		public override function setPlaylistData(data:Object):Boolean
		{
			var xmlPlaylist:XML = XML(data);
			if (xmlPlaylist.namespace() == XSPF4X.xspfNamespace)
			{
				_xspf = new XSPF4X(xmlPlaylist);
				createPlaylist(_xspf.trackList);
				return true;
			}
			else
			{
				return false;
			}
		}
        
        /** 
         * @inheritDoc
         */
        public override function get playlistName():String
        {
            return _xspf.title;
        }
        
        private function createPlaylist(trackList:ArrayCollection):void
        {
        	_tracklist = new ArrayCollection();
        	for each (var track:XSPFTrack in trackList)
        	{
        		var xspfITrack:XSPFiTrack = new XSPFiTrack(track);
        		_tracklist.addItem(xspfITrack);
        	}
        }
    }
}